# @Author: qingsong-Liu
# @Date:   2019-10-22 15:06:20
# @Last Modified by:   qingsong-Liu
# @Last Modified time: 2019-10-22 16:11:17
#!/bin/sh

GIT_HOME=/developer/git-repository/
DEST_PATH=/product/frontend/

if [ ! -n "$1" ];
then 
    echo -e "Please input a project name! You can input as follows:"
    echo -e "./fe-deploy.sh admin-fe"
    exit
fi

if [ $1 = "admin-fe" ];
then
    echo -e "-----------Enter Project-----------"
    cd $GIT_HOME$1
else
    echo -e "Invalid Project Name!"
    exit
fi

# clean dist
echo -e "-----------Clean Dist-----------"
rm -rf ./dist

echo -e "-----------Git Pull-----------"
git pull

echo -e "-----------Yarn Install-----------"
yarn

echo -e "-----------Yarn Run Dist-----------"
yarn run dist

if [ -d "./dist" ]
then
    echo -e "-----------clean Dest-----------"
    rm -rf $DEST_PATH/$1/dist

    echo -e "-----------copy Dest-----------"
    cp -R ./dist $DEST_PATH/$1/

    echo -e "-----------Deploy Suceess-----------"
else
    echo -e "-----------Deploy Fail-----------"
fi